package cn.org.dian.easycommunicate;

import cn.org.dian.easycommunicate.model.DataCenter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class LocalContentActivity extends Activity implements OnItemClickListener {
    
    private static final String TAG = "WelcomeActivity";
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.local_content_activity);
        
        initLanguageSelectList();
    }

    private void initLanguageSelectList() {
        ListView languageSelectList = (ListView) findViewById(R.id.select_language_list);
        // prepare list adapter
        String[] supportedLanguages = DataCenter.getAllSupportLanguages();
//            getResources().getStringArray(R.array.supported_languages);
        ListAdapter listAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, supportedLanguages);
        languageSelectList.setAdapter(listAdapter);
        languageSelectList.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
        Log.d(TAG, "user click pos: " + position + " id: " + id);
        // pass position parameter to next Activity as language indicator
        Intent intent = new Intent(this, ThemeSelectActivity.class);
        intent.putExtra("language_indicator", position);
        startActivity(intent);
    }
    
    @Override
    public void onBackPressed() {
        Activity parent = getParent();
        if (null != parent) {
            parent.onBackPressed();
        } else {
            super.onBackPressed();
        }
    }
}